<!--xyl-->
<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../css/style.css">
        <script src="../plugins/echarts/echarts.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <link rel="stylesheet" href="../plugins/elementui/index.css">

    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>统计分析<small>每日预约、到诊数量统计</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>统计分析</el-breadcrumb-item>
                    <el-breadcrumb-item>每日预约、到诊数量统计</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <!--日期选择器-->
                    <div class="block">
                        <span class="demonstration">带快捷选项</span>
                        <el-date-picker
                                v-model="value2"
                                type="daterange"
                                align="right"
                                unlink-panels
                                range-separator="至"
                                start-placeholder="开始日期"
                                end-placeholder="结束日期"
                                :picker-options="pickerOptions"
                                @change="dateChange">
                        </el-date-picker>
                    </div>
                    <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
                    <div id="chart1" style="height:600px;"></div>
                </div>
            </div>
        </div>
    </body>
    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/axios-0.18.0.js"></script>

    <script>

        var begin_time = new Date();
        var end_time = new Date();
        var b;
        var e;
        new Vue({
            el:'#app',
            data() {
                return {
                    pickerOptions: {
                        shortcuts: [{
                            text: '最近一周',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                                picker.$emit('pick', [start, end]);
                            }
                        }, {
                            text: '最近一个月',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                                picker.$emit('pick', [start, end]);
                            }
                        }, {
                            text: '最近三个月',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                                picker.$emit('pick', [start, end]);
                            }
                        }]
                    },
                    value2: [begin_time,end_time]
                };
            },
            methods:{
                dateChange(){
                    /*alert(this.value2[0]);
                    alert(this.value2[1]);*/
                    axios.get("/charts/getVisitAndOrderPeopleNumber.do?date1="
                        +this.value2[0].getFullYear()+"-"+(this.value2[0].getMonth()+1)+"-"+this.value2[0].getDate()
                        +"&date2="+this.value2[1].getFullYear()+"-"+(this.value2[1].getMonth()+1)+"-"+this.value2[1].getDate()).then((res)=>{
                        if (res.data.flag){
                            myChart1.setOption({
                                title: {
                                    text: '折线图堆叠'
                                },
                                tooltip: {
                                    trigger: 'axis'
                                },
                                legend: {
                                    data: ['每日预约数', '每日到诊数']
                                },
                                grid: {
                                    left: '3%',
                                    right: '4%',
                                    bottom: '3%',
                                    containLabel: true
                                },
                                toolbox: {
                                    feature: {
                                        saveAsImage: {}
                                    }
                                },
                                xAxis: {
                                    type: 'category',
                                    boundaryGap: false,
                                    data: res.data.data.datelist
                                },
                                yAxis: {
                                    type: 'value'
                                },
                                series: [
                                    {
                                        name: '每日预约数',
                                        type: 'line',
                                        stack: '每日预约数',
                                        data: res.data.data.orderlist
                                    },
                                    {
                                        name: '每日到诊数',
                                        type: 'line',
                                        stack: '每日到诊数',
                                        data: res.data.data.visitlist
                                    }
                                ]
                            });
                        }else {
                            this.$message.error(res.data.message);
                        }
                    });
                }
            }
        });

        // 基于准备好的dom，初始化echarts实例
        var myChart1 = echarts.init(document.getElementById('chart1'));
        // 使用刚指定的配置项和数据显示图表。
        axios.get("/charts/getVisitAndOrderPeopleNumber.do?date1="
            +begin_time.getFullYear()+"-"+(begin_time.getMonth()+1)+"-"+begin_time.getDate()
            +"&date2="+end_time.getFullYear()+"-"+(end_time.getMonth()+1)+"-"+end_time.getDate()).then((res)=>{
            if (res.data.flag){
                myChart1.setOption({
                    title: {
                        text: '折线图堆叠'
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        data: ['每日预约数', '每日到诊数']
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    toolbox: {
                        feature: {
                            saveAsImage: {}
                        }
                    },
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: res.data.data.datelist
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: '每日预约数',
                            type: 'line',
                            stack: '每日预约数',
                            data: res.data.data.orderlist
                        },
                        {
                            name: '每日到诊数',
                            type: 'line',
                            stack: '每日到诊数',
                            data: res.data.data.visitlist
                        }
                    ]
                });
            }else {
                this.$message.error(res.data.message);
            }
        });
    </script>

<script type="text/javascript">
    function getDateParament(str) {
        var strList = str.split(",");
        let date = new Date(strList[0]);
        b = strList[0];
        e = strList[1];
    }
</script>
</html>
